package reflect;

import java.util.Arrays;

/**
 * jdk5之后，java提供了一个特性：变长参数
 * */
public class ArgDemo {
    public static void main(String[] args) {
         /*
            为变长参数传参时会被编译器统一改为数组
            doSome();->doSome(new String[]{})
            doSome("a");->doSome(new String[]{"a"})
            doSome("a","b");->doSome(new String[]{"a","b"})
         */
        doSome();
        doSome("a");
        doSome("a","b");
        doSome("a","b","c");
        doSome("a","b","c","d");
        doSome("a","b","c","d","f");
        doSome("a","b","c","d","f","a","b","c","d","f");

    }
    /*
        编译器会将变长参数改为数组
        public static void doSome(String[] arg){

        变长参数有一个要求:它必须是方法的最后一个参数
        public static void doSome(int a,String... arg){
     */
    public static void doSome(String...arg){
        System.out.println(arg.length);
        System.out.println(Arrays.toString(arg));
    }
}
